package com.starview.star.compiler.canonical;

import com.starview.platform.data.type.IType;
import com.starview.platform.data.type.Location;
import com.starview.star.compiler.util.ListUtils;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class Resolved extends BaseExpression
{
  private final IContentExpression over;
  private final IContentExpression dicts[];
  private final IType dictType;

  public Resolved(Location loc, IType type, IType dictType, IContentExpression over, IContentExpression... dicts)
  {
    super(loc, type);
    this.over = over;
    this.dicts = dicts;
    this.dictType = dictType;
    assert over != null && dicts != null && ListUtils.assertNoNulls(dicts);
  }

  public IContentExpression getOver()
  {
    return over;
  }

  public IType getDictType()
  {
    return dictType;
  }

  public IContentExpression[] getDicts()
  {
    return dicts;
  }

  public int getArity()
  {
    return dicts.length;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    over.prettyPrint(disp);
    disp.append("[");
    disp.prettyPrint(dicts, ", ");
    disp.append("]");
  }

  @Override
  public void accept(CanonicalVisitor visitor)
  {
    visitor.visitResolved(this);
  }

  @Override
  public <A, E, P, C, D, T> E transform(TransformExpression<A, E, P, C, D, T> transform, T context)
  {
    return transform.transformResolved(this, context);
  }
}
